<?php
class Product_Model extends ORM{
	
	protected $table_name = 'products';
	protected $primary_key = 'products_id';
	protected $col_sort_order = 'products_sort_order';
	protected $col_status = 'products_status';
	protected $sorting = array('products_sort_order' => 'desc','products_id' => 'desc');
	
	public function get()
	{
		$this->db->from($this->table_name);
		$this->db->select('*');
        $this->db->join('products_description',array('products_description.products_id' => 'products.products_id'));
		$this->db->orderby($this->col_sort_order,'desc');
		$this->db->orderby($this->table_name.'.'.$this->primary_key,'desc');
        $this->db->groupby($this->table_name.'.'.$this->primary_key,'desc');
		$query = $this->db->get();
		return $query->result_array(false);
	}
	
	public function get_with_active()
	{
		$this->db->where($this->col_status,'1');
		return $this->get();
	}
	
	public function getdata($id = '',$type = '',$language='')
	{
		//$language = 1;
		$sql = "products.products_id AS products_id
                ,products.products_image AS products_image, products.products_image2 AS products_image2
                ,products.products_image3 AS products_image3, products.products_image4 AS products_image4
				,products.products_sale_price AS products_sale_price
                ,products.products_msrp_price AS products_msrp_price
                ,products.products_no AS products_no
				,products.products_serial_number AS products_serial_number
				,products.master_categories_id,products_description.products_name AS products_name
                ,products.products_qty AS products_qty
				,products_description.products_summary
				,products_description.products_description,categories_description.categories_name";		
		if($type==1) {
			$sql .=",products.products_wholesale_price AS price";
		} else {
			$sql .=",products.products_our_price AS price";
		}		
		
		$products = $this->db->select($sql)
                    ->from('products')
					->join('products_description','products_description.products_id','products.products_id')
					->join('categories_description','categories_description.categories_id','products.master_categories_id');
					
		if ($language)
			$this->db->where('products_description.languages_id',$language);
			$this->db->where('categories_description.languages_id',$language);
		if ($id)
			$this->db->where('products.products_id',$id);
			$this->db->where('products.products_status',1);
			$this->db->orderby(array('categories_description.categories_id' =>'ASC','products.products_id' =>'DESC'));
		$query = $this->db->get();
		return $query->result_array(false);	
	}	
}
?>